/*
 * util.c
 *
 *  Created on: 2010-03-03
 *      Author: sikorskip
 */
#include <inttypes.h>
#include <avr/io.h>
#include "util.h"

void delay_ms(uint8_t ms) {
	uint16_t delay_count = F_CPU / 17500;
	volatile uint16_t i;
	while (ms != 0) {
		for (i = 0; i != delay_count; i++)
			;
		ms--;
	}
}

void delay(uint8_t sec) {
	uint8_t i = 0;
	for (i = 0; i < sec * 4; i++) {
		delay_ms(250);
	}
}

void setupHW() {
	SPI_init(); // Initialize SPI
	AT45DB011_init(); // Initialize DataFlash
	DS1305_init(); // Initialize RTC SPI
}

char bcd1(const uint8_t bcd) {
	return ((bcd & 0xF0) >> 4) + '0';
}

char bcd2(const uint8_t bcd) {
	return (bcd & 0xF) + '0';
}
